//操作函数-->
//层智能浮动定位
$.fn.smartFloat = function() {
	var position = function(element) {
		var top = element.position().top, pos = element.css("position");
		$(window).scroll(function() {
			var scrolls = $(this).scrollTop();
			if (scrolls > top) {
				if (window.XMLHttpRequest) {
					element.css({
						position: "fixed",
						top: 0
					});	
				} else {
					element.css({
						top: scrolls
					});	
				}
			}else {
				element.css({
					position: pos,
					top: top
				});	
			}
		});
	};
	return $(this).each(function() {
		position($(this));
	});
};
//图片左右切换
$.fn.cutIMG = function() {
	$(this).each(function(i){
		var ul = $(this).children("ul");
		if(ul.children("li").length < 2 ) return 0;
		var l  = "-280px";
		var cut = function(){
			ul.animate({left: l}, 500);
			if(l != "1px") l = "1px";
			else l  = "-280px";
			intervalId = setTimeout(cut,3000);
		}
		var intervalId = setTimeout(cut,3000 + i*1000);
		ul.hover(function(){
			clearInterval(intervalId);
		},function(){
			intervalId = setTimeout(cut,3000);
		});
	});
};
//tabs切换
function tabs(tabTit, on, tabCon){
	$(tabCon).each(function(i){
		$(this).children().hide();
		$(this).children().eq(0).show();
	});
	$(tabTit).each(function(){
		$(this).children().eq(0).addClass(on);
	});
	$(tabTit).children().hover(function(){
		$(this).addClass(on).siblings().removeClass(on);
		var index = $(tabTit).children().index(this);
		$(tabCon).children().eq(index).show().siblings().hide();
	});
};
//店图片切换
(function($){$.fn.slidy=function(settings){if(this.length==0){debug('Selector invalid or missing!');return;}else if(this.length>1){return this.each(function(){$.fn.slidy.apply($(this),[settings]);});}
var opt=$.extend({},$.fn.slidy.defaults,settings),$this=$(this),id=this.attr('id'),elements=$this.children(opt.children),quantity=elements.length,images=(opt.children=='img')?elements:elements.find('img'),timer=0,isAnimate=false;if(id===undefined){id='slidy-'+$this.index();$this.attr('id',id);}
$this.data('options',opt).css({'cursor':opt.cursor,'height':opt.height+'px','overflow':'hidden','position':'relative','width':opt.width+'px'});elements.each(function(i){$(this).css({'position':'absolute','z-index':quantity-i}).attr('id',$this.attr('id')+'-'+(i+1));});images.attr({height:opt.height,width:opt.width}).css('border','0');if(opt.children=='a'&&opt.target!=''){elements.attr('target',opt.target);}
elements.hide().first().show();if(opt.menu){$menu=$('<ul/>',{id:id+'-slidy-menu','class':'slidy-menu'}).insertAfter($this);}
var stop=function(){clearTimeout(timer);},overBanner=function(){stop();},overMenu=function(thiz){stop();var $this=$(this),index=$this.index(),$current=$this.parent().children('.slidy-link-selected'),last=$current.index();if(index!=last){$current.removeClass('slidy-link-selected');$this.addClass('slidy-link-selected');change(last,index);}},outBanner=function(thiz){go($(thiz.target).parent('a').index());},outMenu=function(){var $this=$(this),index=$this.index(),$current=$this.parent().children('.slidy-link-selected'),last=$current.index();go(last);},clickMenu=function(thiz){stop();var $this=$(this),index=$this.index(),$current=$this.parent().children('.slidy-link-selected'),last=$current.index();if(index!=last){$current.removeClass('slidy-link-selected');$this.addClass('slidy-link-selected');}
go(index);};if(opt.menu){var target=(opt.target!='')?'target="'+opt.target+'"':'',menu='',parent,img,quantitynew=0;images.each(function(){img=$(this);title=img.attr('title');if(title){parent=img.parent(opt.children);quantitynew++;menu+='<li><a href="'+parent.attr(parent.is('a')?'href':'title')+'" '+target+'>'+title+'</a></li>';}});$menu.html(menu);var space=parseInt((opt.width/quantitynew)+(quantitynew-1)),diff=opt.width-(space*quantitynew),links=$menu.children('li');if(opt.action=='mouseenter'){links.mouseenter(overMenu).mouseleave(outMenu);}else if(opt.action=='click'){links.click(clickMenu);}else{debug('action attribute must to be "click" or "mouseenter"!');return;}
links.css('width',space).first().addClass('slidy-link-selected').end().last().css({'border-right':'0','width':(space+diff)-(quantitynew-1)});if(opt.animation=='slide'||opt.animation=='fade'){links.mousemove(function(){var $this=$(this);if(!$this.hasClass('slidy-link-selected')){$this.mouseenter();}});}}
go(0);if(opt.pause){$this.mouseenter(overBanner).mouseleave(outBanner);}
function go(index){var total=quantity-1,last=null;if(index>total){index=0;last=total;}else if(index<=0){index=0;last=total;}else{last=index-1;}
change(last,index);timer=setTimeout(function(){go(++index);},opt.time);}
function change(last,index){if(!isAnimate){isAnimate=true;if(opt.animation=='fade'){elements.eq(last).fadeOut(opt.speed).end().eq(index).fadeIn(opt.speed,function(){selectMenu(index);isAnimate=false;});}else if(opt.animation=='slide'){elements.css('z-index',0).eq(index).css('z-index',quantity).slideDown(opt.speed,function(){elements.eq(last).hide();selectMenu(index);isAnimate=false;});}else{elements.eq(last).hide().end().eq(index).show(0,function(){selectMenu(index);isAnimate=false;});}}};function selectMenu(index){if(opt.menu){$this.next('ul.slidy-menu').children().removeClass('slidy-link-selected').eq(index).addClass('slidy-link-selected');}};return $this;};function debug(message){if(window.console&&window.console.log){window.console.log(message);}};$.fn.slidy.defaults={action:'mouseenter',animation:'normal',children:'img',cursor:'default',height:200,menu:false,pause:false,speed:600,target:'',time:3600,width:500};})(jQuery);